﻿using Hidistro.Entities.Commodities;
using Hidistro.SaleSystem.Catalog;
using Hidistro.UI.Common.Controls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace Hidistro.UI.SaleSystem.Tags
{
    public class YB_Juseshangcheng_plist : AscxTemplatedWebControl
    {
        private int categoryId;
        private int pages = 1;
        private Repeater rp;
        private HtmlGenericControl pagelist;
        protected override void AttachChildControls()
        {

            int.TryParse(this.Page.Request.QueryString["Cid"], out this.categoryId);
            if (Page.Request.QueryString["pages"] != null)
            {
                int.TryParse(this.Page.Request.QueryString["pages"], out this.pages);
            }


            int count = 0;
            this.rp = (Repeater)this.FindControl("Rpleft");
            this.pagelist = (HtmlGenericControl)this.FindControl("bt");

            rp.DataSource = ProductBrowser.GetJsProductList(pages, categoryId, out count);
            rp.DataBind();
            if (count > 15)
            {
                if (pages != 1)
                {
                    pagelist.InnerHtml += "<a href=\"/juse/category/plist-" + categoryId +".htm?pages=" + (pages - 1) + "\" class=\"next\">上一页</a>";
                }
                int n = (int)Math.Ceiling((double)count / (double)15);

                string styles = "class=\"selected\"";
                for (int i = 1; i <= n; i++)
                {
                    if (i == pages)
                    {
                        pagelist.InnerHtml += "<a " + styles + " href=\"javascript:;\">"+i+"</a>";
                    }
                    else
                    {
                        pagelist.InnerHtml += " <a href=\"/juse/category/plist-" + categoryId + ".htm?pages=" + i + "\">" + i + "</a>";
                    }
                }
                if (n > pages)
                {
                    pagelist.InnerHtml += "<a href=\"/juse/category/plist-" + categoryId + ".htm?pages=" + (pages + 1) + "\" class=\"next\">下一页</a>";
                }
            }
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "/ascx/tags/YB_Juseshangcheng_pList.ascx";
            }
            base.OnInit(e);
        }
    }
}
